<?php
/**
 * Created by PhpStorm.
 * User: chniccs
 * Date: 2019-09-06
 * Time: 16:45
 */

namespace app\model;


use app\helper\TenantHelper;

class AdminTenant extends Base
{
    public static function doSave($tid, $data, $admin = false)
    {
        $model = AdminTenant::get($tid);
        if ($model) {
            $orgData = $model->getData();
            if (!$admin) {
                $data['expiration_time'] = $model->expiration_time;
            }
            $data = TenantHelper::changeStatus($data);
            $affected = $model->save($data, ['id' => $tid]);
            if ($affected) {
                //设置缓存的域名，用于通过域名来判断前端访问的站点所属
                TenantHelper::removeHostCache($orgData['domain'], $tid);
                TenantHelper::setHostCache($data['domain'], $tid);
                return true;
            } else {
                return false;
            }
        }
        return false;
    }
}